package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-01-25
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
@Api(description="课程分类管理")
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    @PostMapping("addSubject")
    @ApiOperation("excel批量注入")
    public R saveSubject(MultipartFile file){
//        上传文件用MultipartFile
        eduSubjectService.addSubject(file,eduSubjectService);
        return R.ok();
    }


    @GetMapping("getAllSubject")
    @ApiOperation("获取课程树形列表")
    public R getAllSubject(){
        //返回一级包含二级的课程树形结构
        List<OneSubject> finalSubject = eduSubjectService.getOneTwoAllSubject();
      return  R.ok().data("item",finalSubject);
    }


}

